<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=9,IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="renderer" content="webkit">
    <meta charset="UTF-8">
    <title>互动支付</title>
</head>
<link rel="stylesheet" type="text/css" href="<%=basePath%>/app/plugins/dialog/css/dialog.css" />
<body>
<!--active-pay-wrapper-->
<div class="active-pay-wrapper" id="pay_info">
    <script type="text/html" id="tplPay">
        <input type="hidden" id="id" value="{{busi_id}}" />
        <section class="pay-info">
            <p>支付信息</p>
            <h3>￥{{dealAmount price}}元</h3>
        </section>
        <section class="goods-info">
            <ul class="list">
                <li>商品名称：{{busi_name}}</li>
                <li>订单编号： {{order_num}}</li>
            </ul>
        </section>
        <section class="btn-box">
            <button type="button" class="btn-pay" id="btnPay"><span class="wx">微信支付</span></button>
        </section>

        <section class="rule-list">
            <ul class="list">
                <li>规则说明</li>
                <li>1.订单确认后请15分钟内完成支付，否则将自动取消</li>
                <li>2.订单支付成功后，将无法退款</li>
                <li>3.最终解释权归主办方所有</li>
            </ul>
        </section>
    </script>
</div>

<script type="text/javascript" src="<%=basePath%>/app/js/wechat.js"></script>
<script type="text/javascript" src="<%=basePath%>/app/plugins/dialog/js/dialog.js"></script>
<!--/active-pay-wrapper-->
<script type="text/javascript">
    $(function(){
        $.ajax({
            url: _basePath + "app/order/get",
            data:{id:${orderId}},
            dataType: 'json',
            success: function (data) {
                if(typeof data.resultList != undefined && data.resCode == 0){
                    $("#pay_info").append(template('tplPay', data.resultList));
                    mui('body').on('tap', 'button#btnPay', function(){
                        wxPay();
                    });
                }else{
                    mui.toast(data['message']);
                }
            }
        });

        function wxPay() {
            $.dialog({
                titleText : '确认支付?',
                type : 'confirm',
                buttonText : {
                    ok : '去支付',
                    cancel : '我再想想'
                },
                onClickOk : function(){
                    //打开新页面
                    wechatPay(${orderId},location.href,function(){
                        mui.toast("订单提交中，请稍候",{ duration:'long'});
                        setTimeout(function () {
                            $.ajax({
                                url: _basePath + "app/act/fund",
                                data: {
                                    id: ${id},
                                    orderId: ${orderId}
                                },
                                dataType: "json",
                                type: "post",
                                success: function (data) {
                                    if (typeof data != undefined && data.resCode == 0) {
                                        mui.toast("支持成功");
                                        setTimeout(function () {
                                            mui.openWindow({
                                                url: _basePath + "app/page?pv=act_fund&id=${id}"
                                            })
                                        },200);
                                    }else{
                                        mui.toast(data['message'])
                                    }
                                }
                            })
                        },3500);
                    });
                    return true;
                },
                onClickCancel : function(){
                    return true;
                },
                contentHtml : '点击"去支付"前往微信进行支付'
            });
        }

    });
</script>